openapi: 3.0.0
servers:
  - description: Main API
    url: http://localhost:3000/api
info:
  version: "1.0.0"
  title: next-phone-contacts
  description: The API for the next-phone-contacts project

paths:
  /contacts:
    get:
      summary: Get all contacts
      tags:
        - Contacts
      description: Gets a list of all contacts
      operationId: getContacts
      responses:
        '200':
          description: Returns all contacts
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Contacts'
        'default':
          description: All the rest of methods
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    post:
      summary: Create a new contact
      tags:
        - Contacts
      description: Creates a new contact
      operationId: createContact
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  example: 'John Doe'
                email:
                  type: integer
                  example: 'john@test.com'
                phone_mobile:
                  type: string
                  example: '+12345'
                phone_home:
                  type: string
                  example: '+12345'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: 'OK'
        'default':
          description: All the rest of methods
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /contacts/{id}:
    put:
      summary: Update a contact by ID
      tags:
        - Contacts
      description: Updates a contact by ID 
      operationId: updateContact
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Returns an updated contact
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Contact'
        'default':
          description: All the rest of methods
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    delete:
      summary: Delete a contact by ID
      tags:
        - Contacts
      operationId: deleteContact
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Returns a deleted contact
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Contact"
        'default':
          description: All the rest of methods
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

components:
  schemas:
    Contact:
      type: object
      required: 
        - id
        - name
        - email
        - phone_mobile
        - phone_home
      properties:
        id:
          type: integer
          example: 1
        name:
          type: string
          example: 'John Doe'
        email:
          type: string
          example: 'john@test.com'
        phone_mobile:
          type: string
          example: '+12345'
          format: \+(\d{1,50})
        phone_home:
          type: string
          example: '+12345'
          format: \+(\d{1,50})
    Contacts:
      type: array
      items:
        $ref: '#/components/schemas/Contact'
    Error:
      type: object
      required:
        - message
      properties:
        message:
          type: string
          example: Server side error
